<?php

namespace App\Traits;

use App\Services\CommonService;
use Illuminate\Http\Request;

trait ControllerTrait
{
    /**
     * 响应成功。兼容历史接口
     */
    public function responseSuccess($message = '', $data = null, $code = null)
    {
        $code = is_null($code) ? CommonService::HTTP_CODE_SUCCESS : $code;
        return response()->json(['status' => $code, 'msg' => $message ?: 'success', 'data' => $data]);
    }

    /**
     * 响应失败。兼容历史接口
     */
    public function responseFail($message = '', $data = null, $code = null)
    {
        $code = is_null($code) ? CommonService::HTTP_CODE_FAIL : $code;
        $output = ['status' => $code, 'msg' => $message ?: 'fail', 'data' => $data];
        return response()->json($output);
    }
}
